package medium;


/**
 * @author liujianxin
 * @date 2019-08-03 17:19
 */
public class AddTwoNumbers {

    public static void main(String[] args) {
        String num1 = "18";
        String num2 = "0";
        byte n = 0;
        int adder = 0;
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < Math.max(num1.length(), num2.length()); i++) {
            if (i < num1.length() && i < num2.length()) {
                adder = n + (num1.charAt(i) + num2.charAt(i)) - 2 * '0';
                if (adder >= 10) {
                    n = 1;
                    adder -= 10;
                } else {
                    n = 0;
                }
            } else {
                String winner = num1.length() > i ? num1 : num2;
                adder = winner.charAt(i) - '0';
            }
            sb.append(adder);
        }
        StringBuilder reverse = sb.reverse();
        ListNode current = null;
        ListNode next = null;
        for (int inex = 0; inex < reverse.length(); inex++) {
            current = new ListNode(reverse.charAt(inex) - '0');
            current.next = next;
            next = current;
        }

    }


    public ListNode addTwoNumbers(ListNode l1, ListNode l2) {
        return null;
    }

    private String getNum(ListNode l1) {
        StringBuilder sb = new StringBuilder();
        do {
            sb.append(l1.val);
            l1 = l1.next;
        } while (l1 != null);
        return sb.toString();
    }


    private static class ListNode {
        int val;
        ListNode next;

        public ListNode(int val) {
            this.val = val;
        }

    }
}
